<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function back(){
		var uri = "./contract.do";
		var sign = "<c:out value='${sign}'/>";
		if(sign == "1"){//返回到执行中合同
			uri = "./contract.do";
		}else if(sign == "2"){//返回到待审的合同
			uri = "./contract.do?action=preWaitAduitContract";
		}else if(sign == "3"){//返回到退回的合同
			uri = "./contract.do?action=preReturnContract";
		}else if(sign == "4"){//返回到历史档案页面
			uri = "./contract.do?action=preClosedContract";
		}else if(sign == "5"){//返回到部门合同页面
			uri = "./contract.do?action=preDeptContract";
		}else if(sign == "61"){//返回到应收帐款页面
			uri = "./contractBackCost.do";
		}else if(sign == "62"){//返回到部门应收帐款页面
			uri = "./contractBackCost.do?action=deptBackCostManage";
		}else if(sign == "7"){//返回到审核管理－待审核合同页面
			uri = "./auditManage.do?action=preAuditContract";
		}else if(sign == "299"){
			uri = "./manageReport.do?action=CustomerStatisticContract";
			}else if(sign == "290"){
			uri = "./manageReport.do?action=saleStatisticContract";
			}
		window.location.href = uri;
		window.location.target = "main";
	}
	
	function downloadAdded(addedId){
		document.contractDetailForm.action = "./contract.do?action=downloadAdded&addedId="+addedId;
		document.contractDetailForm.target = "main";
		document.contractDetailForm.submit();
	}
	
	function contractUpdateHistory(id){
		document.contractDetailForm.action = "./contract.do?action=contractUpdateHistory";
		document.contractDetailForm.target = "main";
		document.contractDetailForm.submit();
	}
	
	function backcostBuiltInvoice(){
		document.contractDetailForm.action = "./contract.do?action=viewBackCostInvoice";
		document.contractDetailForm.target = "main";
		document.contractDetailForm.submit();
	}

	function showHidden(id){
		var obj = document.getElementById(id);
		if(obj.style.display == "none"){
			document.getElementById(id).style.display = "block";
			document.getElementById("img"+id).src = "./images/nolines_minus.gif";
		}else{
			document.getElementById(id).style.display = "none";
			document.getElementById("img"+id).src = "./images/nolines_plus.gif";
		}
	}
	
	function officialCostGen()
	{
		var caseIds = "";
		
		var caseAry = document.getElementsByName("contractCaseCheck");
		for(var i=0; i<caseAry.length; i++)
		{
			if(caseAry[i].checked)
				caseIds += caseAry[i].value+"/";
		}
		
		if(caseIds != "")
			caseIds = caseIds.substring(0, caseIds.length-1);
		else
		{
			alert("请选择一个案件。");
			return false;
		}			
		
		document.contractDetailForm.action = "./contract.do?action=preOfficialCostGen&caseIds="+caseIds;
		document.contractDetailForm.target = "main";
		document.contractDetailForm.submit();		
	}
	
	function operationCostGen()
	{
		var caseIds = "";
		
		var caseAry = document.getElementsByName("contractCaseCheck");
		for(var i=0; i<caseAry.length; i++)
		{
			if(caseAry[i].checked)
				caseIds += caseAry[i].value+"/";
		}
		
		if(caseIds != "")
			caseIds = caseIds.substring(0, caseIds.length-1);
		else
		{
			alert("请选择一个案件。");
			return false;
		}			
		
		document.contractDetailForm.action = "./contract.do?action=preOperationCostGen&caseIds="+caseIds;
		document.contractDetailForm.target = "main";
		document.contractDetailForm.submit();		
	}	
-->
</script>
</head>
<body>
<form name="contractDetailForm" action="" method="post">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab">
							合同全貌
						</td>
					</tr>
					<tr>
						<td align="center" valign="bottom">
							<button class="btn_submit" onclick="contractUpdateHistory()" hidefocus="true">查看变更记录</button>&nbsp;&nbsp;
							<button class="btn_back" onclick="back()" hidefocus="true">返回</button>
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td valign="top">
				<table class="table_title2">
					<tr onclick="showHidden('1')">
						<td class="title_info">
							<img id="img1" src="./images/nolines_minus.gif">
							合同基本信息
						</td>
					</tr>
					<tr id="1">
						<td>
							<table class="table_add" style="display: block;">
								<tr>
									<td class="title">合同编号：</td>
									<td>${contract.contractCode}<input id="id" name="id" type="hidden" value="${contract.id}"/></td>
									<td class="title">合同名称：</td>
									<td>${contract.contractName}</td>
								</tr>
								<tr>
									<td class="title">合同总金额：</td>
									<td>￥<font color="red">${contract.contractCost}</font>元</td>
									<td class="title">签约时间：</td>
									<td><fmt:formatDate value="${contract.contractDate}" pattern="yyyy-MM-dd"/></td>
								</tr>
								<tr>
									
									<td class="title">销售代表：</td>
									<td >${contract.salePerson}</td>
									<td class="title">制单日期：</td>
									<td ><fmt:formatDate value="${contract.createDate}" pattern="yyyy-MM-dd"/></td>
								</tr>
								<tr>
									<td class="title">审核人：</td>
									<td >${contract.auditPerson}</td>
									<td class="title">审核日期：</td>
									<td ><fmt:formatDate value="${contract.auditDate}" pattern="yyyy-MM-dd HH:mm"/></td>
								</tr>
								<tr>
									<td class="title">备注：</td>
									<td class="" colspan="3"><pre>${contract.contractDesc}</pre></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr><td height="10"></td></tr>
		<tr>
			<td valign="top">
				<table class="table_title2">
					<tr onclick="showHidden('2')">
						<td class="title_info">
							<img id="img2" src="./images/nolines_minus.gif">案件信息
							&nbsp;
							<input class="btn_append" type="button" value="官费发起" onclick="javascript:officialCostGen()" hidefocus="true"/>
							&nbsp;
							<input class="btn_append" type="button" value="业务费用发起" onclick="javascript:operationCostGen()" hidefocus="true"/>
						</td>
					</tr>
					<tr id="2" style="display: block;">
						<td>
							<table class="table_style">
								<tr>
									<td class="title" width="8"></td>
									<td class="title">商品名称</td>
									<td class="title" width="8%">当前进度</td>
									<td class="title" width="12%">总金额</td>
									<td class="title" width="12%">官费</td>
									<td class="title" width="12%">业务费用</td>
									<td class="title" width="12%">代理费用</td>
								</tr>
								<c:forEach var="contractCase" items="${contractCases}">
									<tr onmouseover="onmousemoveChange(this,'img${contractCase.id}')" onmouseout="onmouseoutChange(this,'img${contractCase.id}')">
										<td height="16" width="8" align="right"><img id="img${contractCase.id}" src="./images/table_sign2.bmp"></td>
										<td align="left">
											<input id="contractCaseCheck" name="contractCaseCheck" type="checkbox" value="${contractCase.id}"/>
											&nbsp;&nbsp;
											${contractCase.caseCode}
										</td>
										<td>${contractCase.processName}</td>
										<td>
											${contractCase.costValue}
										</td>
										<td>
											${contractCase.officialCost}
										</td>
										<td>
											${contractCase.operationCost}
										</td>
										<td>
											${contractCase.proxyCost}
										</td>
									</tr>
								</c:forEach>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr><td height="10"></td></tr>
		<tr>
			<td valign="top">
				<table class="table_title2">
					<tr onclick="showHidden('3')">
						<td class="title_info">
							<img id="img3" src="./images/nolines_minus.gif">
							应收账款
						</td>
					</tr>
					<tr id="3">
						<td>
							<table class="table_add">
								<tr>
									<td class="title">合同总额：</td>
									<td>${contract.contractCost}元</td>
									<td class="title">回款累计：</td>
									<td>${contract.backCost}元</td>
								</tr>
								<tr>
									<td class="title">回款次数：</td>
									<td>${contract.backCostNum}次</td>
									<td class="title">应收余额：</td>
									<td>${contract.receivable}元</td>
								</tr>
							</table>
							<table class="table_style">
								<tr>
									<td class="title" width="8"></td>
									<td class="title" width="30">业绩</td>
									<td class="title" width="12%">回款类型</td>
									<td class="title" width="12%">回款金额(元)</td>
									<td class="title" width="12%">收入类型</td>
									<td class="title" width="12%">付款类型</td>
									<td class="title" width="12%">付款方式</td>
									<td class="title" width="12%">回款日期</td>
									<td class="title" width="12%">销售代表</td>
									<td class="title">备注</td>
								</tr>
								<c:forEach var="backCost" items="${backCosts}">
								<tr onmouseover="onmousemoveChange(this,'img${backCost.id}')" onmouseout="onmouseoutChange(this,'img${backCost.id}')">
									<td height="16" width="8" align="right"><img id="img${backCost.id}" src="./images/table_sign2.bmp"></td>
									<td><input id="" name="" type="checkbox" <c:if test='${backCost.grossBackCostId == 2 && backCost.businessStatus == 1}'>checked</c:if> disabled /></td>
									<td>
										<c:choose>
											<c:when test="${backCost.grossBackCostId == 1}">成本</c:when>
											<c:when test="${backCost.grossBackCostId == 2}">毛利</c:when>
										</c:choose>
									</td>
									<td>${backCost.cost}</td>
									<td>
										<c:forEach var="range" items="${ranges['35']}">
										 <c:if test='${backCost.incomeTypeId == range.id}'>${range.rangeValue}</c:if>
										</c:forEach>										
									</td>
									<td>
									<c:forEach var="range" items="${ranges['32']}">
										<c:if test="${range.id == backCost.backCostTypeId}">${range.rangeValue}</c:if>
									</c:forEach>
									</td>
									<td>
									<c:forEach var="range" items="${ranges['33']}">
										<c:if test="${range.id == backCost.backCostWayId}">${range.rangeValue}</c:if>
									</c:forEach>
									</td>
									<td><fmt:formatDate value="${backCost.backDate}" pattern="yyyy-MM-dd"/></td>
									<td>${backCost.salePerson}</td>
									<td>${backCost.backCostDesc}</td>
								</tr>
								</c:forEach>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr><td height="10"></td></tr>
		<tr>
			<td valign="top">
				<table class="table_title2">
					<tr onclick="showHidden('4')">
						<td class="title_info">
							<img id="img4" src="./images/nolines_minus.gif">
							开票记录
						</td>
					</tr>
					<tr id="4">
						<td>
							<table class="table_style">
								<tr>
									<td class="title" width="8"></td>
									<td class="title" width="12%">开票时间</td>
									<td class="title" width="12%">领票人</td>
									<td class="title" width="12%">总金额</td>
									<td class="title" width="12%">发票号码</td>
									<td class="title" width="12%">备注信息</td>
									<td class="title">红冲发票号</td>
								</tr>
								<c:forEach var="invoice" items="${invoices}">
								<tr onmouseover="onmousemoveChange(this,'img${invoice.id}')" onmouseout="onmouseoutChange(this,'img${invoice.id}')">
									<td height="16" width="8" align="right"><img id="img${invoice.id}" src="./images/table_sign2.bmp"></td>
									<td><fmt:formatDate value="${invoice.invoiceDate}" pattern="yyyy-MM-dd"/></td>
									<td>${invoice.invoicePerson}</td>
									<td>${invoice.invoiceCost}</td>
									<td>${invoice.invoiceCode}</td>
									<td>${invoice.invoiceDesc}</td>
									<td></td>
								</tr>
								</c:forEach>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr><td height="10"></td></tr>
		<tr>
			<td valign="top">
				<table class="table_title2">
					<tr onclick="showHidden('5')">
						<td class="title_info">
							<img id="img5" src="./images/nolines_plus.gif">
							合同附件信息
						</td>
					</tr>
					<tr id="5" style="display: none;">
						<td>
							<table class="table_style">
								<tr>
									<td class="title" width="8"></td>
									<td class="title">附件名称</td>
									<td class="title" width="12%">上传者</td>
									<td class="title" width="12%">上传时间</td>
									<td class="title" width="12%">操作</td>
								</tr>
								<c:forEach var="systemFile" items="${contractAddeds}" varStatus="sf">
								<tr onmouseover="onmousemoveChange(this,'img${sf.count}')" onmouseout="onmouseoutChange(this,'img${sf.count}')">
									<td height="16" width="8" align="right"><img id="img${sf.count}" src="./images/table_sign2.bmp"></td>
									<td align="">${systemFile.fileName}</td>
									<td>${systemFile.person}</td>
									<td><fmt:formatDate value="${systemFile.uploadDate}" pattern="yyyy-MM-dd"/></td>
									<td>
										<img class="btn_img" src="./images/a_upload.gif" onclick="downloadAdded('${systemFile.id}')" title="下载附件">
									</td>
								</tr>
								</c:forEach>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<input id="sign" name="sign" type="hidden" value="${sign}"/>
	<input id="customerId" name="customerId" type="hidden" value="${contract.customerId}"/>
</form>
</body>
</html>